<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="./js/jquery-3.1.1.js"></script>
    <link rel="stylesheet" href="/css/login.css">
    <title>登录</title>
    <style>
    </style>
</head>
<body>

<div class="login-container">
    <h2>星龙小说网</h2>
    <form id="login-form" action="http://localhost:8080/demoMVC/LoginController" method="get">
        <input id="acc" type="text" name="username" placeholder="请输入账号">
        <br>
        <span style="color: red"></span>
        <input id="pwd" type="password" name="userpassword" placeholder="请输入密码">
        <br>
        <input onclick="login()" type="button" value="登录">
    </form>
    <div class="register-link">
        没有账号？<a href="/register.html">点击注册</a>
    </div>
</div>

</body>

<script type="text/javascript">
    //js的入口函数
    $(document).ready(function () {
        //初始化代码，比如绑定事件等
    });

    function login() {
        console.log($("#login-form").serialize());
        //                                  serialize() 序列化传参
        $.get("http://localhost:8080/login", $("#login-form").serialize(),function(data)
        {
            console.log(data)
            if (data === "登录成功") {
                location.href = "index.html";
            }else {
                // alert("登录失败！")
                $("span").text(data); // 显示错误信息
            }
        });

    }
    /* function checklogin() {
	// 使用load函数加载数据
	$("#span").load(
			// 参数1 url
			"http://localhost:8080/demosession/userloginservlet",
			// 参数2 json数据
			{"账号":$("#acc").val(),"密码":$("#pwd").val()},
			// 回调函数
			function(data){
				console.log(data)
				if(data == "登录成功！"){
					location.href="http://localhost:8080/demosession/listgoodsservlet"
				}
			}); */

</script>
</html>